package balmysundaycandy.more.low.level.logger;

import java.util.HashMap;
import java.util.Map;

import com.google.appengine.repackaged.com.google.io.protocol.ProtocolMessage;
import com.google.appengine.repackaged.com.google.protobuf.GeneratedMessage;
import com.google.apphosting.api.ApiBasePb.Integer64Proto;
import com.google.apphosting.api.ApiBasePb.StringProto;
import com.google.apphosting.api.ApiBasePb.VoidProto;
import com.google.apphosting.api.DatastorePb.AllocateIdsRequest;
import com.google.apphosting.api.DatastorePb.AllocateIdsResponse;
import com.google.apphosting.api.DatastorePb.CommitResponse;
import com.google.apphosting.api.DatastorePb.CompositeIndices;
import com.google.apphosting.api.DatastorePb.Cursor;
import com.google.apphosting.api.DatastorePb.DeleteRequest;
import com.google.apphosting.api.DatastorePb.DeleteResponse;
import com.google.apphosting.api.DatastorePb.GetRequest;
import com.google.apphosting.api.DatastorePb.GetResponse;
import com.google.apphosting.api.DatastorePb.GetSchemaRequest;
import com.google.apphosting.api.DatastorePb.NextRequest;
import com.google.apphosting.api.DatastorePb.PutRequest;
import com.google.apphosting.api.DatastorePb.PutResponse;
import com.google.apphosting.api.DatastorePb.Query;
import com.google.apphosting.api.DatastorePb.QueryExplanation;
import com.google.apphosting.api.DatastorePb.QueryResult;
import com.google.apphosting.api.DatastorePb.RunCompiledQueryRequest;
import com.google.apphosting.api.DatastorePb.Schema;
import com.google.apphosting.api.DatastorePb.Transaction;
import com.google.storage.onestore.v3.OnestoreEntity.CompositeIndex;

/**
 * hold protocol buffer object with key. key is composed by service name and
 * method name.
 * 
 * @author marblejenka
 * 
 */
public class ProtocolBufferObjectHolder {
	/**
	 * hold protocol message request objects.
	 */
	public static final Map<ProtocolBufferKey, ProtocolMessage<?>> protocolmessagerequests = new HashMap<ProtocolBufferKey, ProtocolMessage<?>>();

	/**
	 * hold protocol message response objects.
	 */
	public static final Map<ProtocolBufferKey, ProtocolMessage<?>> protocolmessageresponses = new HashMap<ProtocolBufferKey, ProtocolMessage<?>>();

	/**
	 * hold generated message request objects.
	 */
	public static final Map<ProtocolBufferKey, GeneratedMessage> generatedmessagerequests = new HashMap<ProtocolBufferKey, GeneratedMessage>();

	/**
	 * hold generated message response objects.
	 */
	public static final Map<ProtocolBufferKey, GeneratedMessage> generatedmessageresponses = new HashMap<ProtocolBufferKey, GeneratedMessage>();

	static {
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "Get"), new GetRequest());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "Put"), new PutRequest());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "Delete"), new DeleteRequest());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "RunQuery"), new Query());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "RunCompiledQuery"), new RunCompiledQueryRequest());
		// XXX actionresponse cause noclassdeffounderror
		// protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3",
		// "AddAction"), new ActionRequest());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "Next"), new NextRequest());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "Count"), new Query());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "Explain"), new Query());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "DeleteCursor"), new Cursor());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "BeginTransaction"), new VoidProto());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "Commit"), new Transaction());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "Rollback"), new Transaction());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "GetSchema"), new GetSchemaRequest());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "AllocateIds"), new AllocateIdsRequest());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "CreateIndex"), new CompositeIndex());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "UpdateIndex"), new CompositeIndex());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "GetIndices"), new StringProto());
		protocolmessagerequests.put(new ProtocolBufferKey("datastore_v3", "DeleteIndex"), new CompositeIndex());

		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "Get"), new GetResponse());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "Put"), new PutResponse());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "Delete"), new DeleteResponse());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "RunQuery"), new QueryResult());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "RunCompiledQuery"), new QueryResult());
		// XXX actionresponse cause noclassdeffounderror
		// protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3",
		// "AddAction"), new ActionResponse());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "Next"), new QueryResult());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "Count"), new Integer64Proto());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "Explain"), new QueryExplanation());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "DeleteCursor"), new VoidProto());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "BeginTransaction"), new Transaction());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "Commit"), new CommitResponse());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "Rollback"), new VoidProto());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "GetSchema"), new Schema());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "AllocateIds"), new AllocateIdsResponse());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "CreateIndex"), new Integer64Proto());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "UpdateIndex"), new VoidProto());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "GetIndices"), new CompositeIndices());
		protocolmessageresponses.put(new ProtocolBufferKey("datastore_v3", "DeleteIndex"), new VoidProto());
	}

}
